package com.xfp.controller;

import com.xfp.pojo.dto.GoodsDto;
import com.xfp.pojo.dto.GoodsQueryDto;
import com.xfp.pojo.vo.GoodsQueryVo;
import com.xfp.pojo.vo.GoodsVo;
import com.xfp.result.Result;
import com.xfp.service.GoodsService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@Api(tags = "商品接口")
@RequestMapping("/api/vm-service/sku")
@Slf4j
public class GoodsController {

    @Autowired
    private GoodsService goodsService;

    /**
     * 新增商品
     * @param goodsDto
     * @return
     */
    @PostMapping
    @ApiOperation("新增商品")
    private Result<Boolean> insert(@RequestBody GoodsDto goodsDto){
        log.info("新增接口：{}",goodsDto);
        Boolean b = goodsService.insert(goodsDto);
        return Result.success(b);
    }

    /**
     * 分页查询商品
     * @param goodsQueryDto
     * @return
     */
    @GetMapping("/search")
    @ApiOperation("商品分页查询")
    public GoodsQueryVo page(GoodsQueryDto goodsQueryDto){
        log.info("商品分页查询：{}",goodsQueryDto);
        GoodsQueryVo goodsQueryVo = goodsService.page(goodsQueryDto);
        return goodsQueryVo;
    }

    @PutMapping("/{skuId}")
    @ApiOperation("修改商品信息")
    public Result<Boolean> update(@PathVariable String skuId,@RequestBody GoodsDto dto){
        log.info("修改商品信息：{}，{}",skuId,dto);
        Boolean b = goodsService.update(skuId,dto);
        return Result.success(b);
    }


}
